package com.mycompany.mvc.filter;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class urlEncodeFilter implements Filter{

    Logger logger = LoggerFactory.getLogger(urlEncodeFilter.class);
    Map<String,Object> paramMap = new HashMap<String,Object>();

    @Override
    public void destroy() {
    }

    @Override
    public void doFilter(ServletRequest arg0, ServletResponse arg1,
                         FilterChain arg2) throws IOException, ServletException {
        System.out.println("urlEncodeFilter doFilter..."+paramMap.get("urlEncode").toString());
        arg0.setCharacterEncoding(paramMap.get("urlEncode").toString());
        arg1.setCharacterEncoding(paramMap.get("urlEncode").toString());
        arg2.doFilter(arg0, arg1);
    }

    @Override
    public void init(FilterConfig arg0) throws ServletException {
        String urlEncode = arg0.getInitParameter("urlEncode");
        paramMap.put("urlEncode",urlEncode);
    }

} 